package com.jack.concurrency;

/**
 * Created by zhang_j on 2019/12/2
 * 可重入：若一个程序或子程序在任意时刻被中断然后操作系统调度执行另外一段代码，这段代码又调用了该子程序不会出错，则称其为可重入的。
 */
public class SyncIsReentrant extends SuperFather {

    public static void main(String[] args) {
        SyncIsReentrant child = new SyncIsReentrant();
        child.doSomething();
    }

    @Override
    public synchronized void doSomething(){
        System.out.println("child.doSomething():"+Thread.currentThread().getName());
        doAnotherThing();
    }

    public synchronized void doAnotherThing(){
        super.doSomething();
        System.out.println("child.doAnotherThing():"+Thread.currentThread().getName());
    }
}
class SuperFather{

    public synchronized void doSomething(){
        System.out.println("father.doSomething():"+Thread.currentThread().getName());
    }
}